﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BusinessLogic;
using Entities;

namespace DangKyOnline
{
    public partial class DangKy : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack == false)
            {
                KhoiTaoGiaTriBanDau();
            }
        }

        protected void cmdCapNhat_Click(object sender, EventArgs e)
        {

            DoiTuongGhiDanh objDoiTuongGhiDanh = new DoiTuongGhiDanh();
            objDoiTuongGhiDanh.MaDoiTuong = "";
            objDoiTuongGhiDanh.TenDoiTuong = TxtHoTen.Text;
            objDoiTuongGhiDanh.NgaySinh = Convert.ToDateTime(txtNgaySinh.Text) ;
            objDoiTuongGhiDanh.QuocTich = Convert.ToInt32(ddlQuocTich.SelectedValue);
            objDoiTuongGhiDanh.DiaChiThuongTru = txtDiaChiThuongTru.Text;
            objDoiTuongGhiDanh.DiaChiCuTru = txtDiaChiCuTru.Text;

            PhieuGhiDanh objPhieuGhiDanh = new PhieuGhiDanh();
            objPhieuGhiDanh.Khoa = -1;
            objPhieuGhiDanh.KhoaHoc = Convert.ToInt32(ddlKhoaHoc.SelectedValue);
            objPhieuGhiDanh.HangXe = Convert.ToInt32(ddlHangXeTheoHoc.SelectedValue);
            objPhieuGhiDanh.HocNgoaiGio = Convert.ToInt32(chkHocNgoaiGio.Checked);

            Session["DoiTuongGhiDanh"] = objDoiTuongGhiDanh;
            Session["PhieuGhiDanh"] = objDoiTuongGhiDanh;

            Response.Redirect("XacNhanThongTin.aspx");

        }

        private void KhoiTaoGiaTriBanDau()
        {
            KhoiTaoQuocTich();
            KhoiTaoKhoaHoc();
            KhoTaoHangXeTheoHoc();
        }

        private void KhoTaoHangXeTheoHoc()
        {
            try
            {
                DataTable dtHangXe = null;
                HangXeBL objHangXeBL = new HangXeBL();
                dtHangXe = objHangXeBL.SelectAll();
                ddlHangXeTheoHoc.DataSource = dtHangXe;
                ddlHangXeTheoHoc.DataTextField = "MaHangXe";
                ddlHangXeTheoHoc.DataValueField = "Khoa";
                ddlHangXeTheoHoc.DataBind();

            }
            catch (Exception exc)
            {

            }
        }

        private void KhoiTaoKhoaHoc()
        {
            try
            {
                DataTable dtKhoaHoc = null;
                KhoaHocBL objKhoaHocBL = new KhoaHocBL();
                dtKhoaHoc = objKhoaHocBL.SelectAll();
                ddlKhoaHoc.DataSource = dtKhoaHoc;
                ddlKhoaHoc.DataTextField = "MaKhoaHoc";
                ddlKhoaHoc.DataValueField = "Khoa";
                ddlKhoaHoc.DataBind();

            }
            catch (Exception exc)
            { 
            
            }
        }

        private void KhoiTaoQuocTich()
        {
            try
            {
                DataTable dtQuocGia = null;
                QuocGiaBL objQuocGiaBL = new QuocGiaBL();
                dtQuocGia = objQuocGiaBL.SelectAll();
                ddlQuocTich.DataSource = dtQuocGia;
                ddlQuocTich.DataTextField = "TenQuocGia";
                ddlQuocTich.DataValueField = "Khoa";
                ddlQuocTich.DataBind();
            }
            catch (Exception exc)
            { 
                
            }
        }

      

      
    }
}